#define _CRT_SECURE_NO_WARNINGS 1
int BinarySize(struct TreeNode* root)
{
    return root == NULL ? 0 : BinarySize(root->left) + BinarySize(root->right) + 1;
}

void _preorderTraversal(struct TreeNode* root, int* returnRoot, int* count)
{
    if (root == NULL)
        return;

    returnRoot[(*count)++] = root->val;
    _preorderTraversal(root->left, returnRoot, count);
    _preorderTraversal(root->right, returnRoot, count);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize)
{
    *returnSize = BinarySize(root);
    int* returnRoot = (int*)malloc(sizeof(int) * (*returnSize));
    int count = 0;
    _preorderTraversal(root, returnRoot, &count);
    return returnRoot;
}